//第三方包gojson 一些例子
//这个有些部分比较方便 有些则没有官方的json好使
package main

import (
	"fmt"
	"github.com/widuu/gojson"
)

func main() {
	json := `{"from":"en","to":"zh","trans_result":{"src":"today","dst":"\u4eca\u5929"},"result":["src","today","dst","\u4eca\u5929"]}`
	c1 := gojson.Json(json) //&{map[from:en to:zh]}
	fmt.Println(c1)

	c2 := c1.Get("from")
	fmt.Println(c2)

	c3 := c2.Tostring()
	fmt.Println(c3)

	c4 := gojson.Json(json).Getpath("trans_result", "src").Tostring()
	fmt.Println(c4) //today

	c7 := gojson.Json(json).Get("result").Arrayindex(1)
	fmt.Println(c7) //src

	json1 := `{"from":"en","to":"zh","trans_result":[{"src":"today","dst":"\u4eca\u5929"},{"src":"tomorrow","dst":"\u660e\u5929"}]}`
	c8 := gojson.Json(json1).Get("trans_result").Getkey("src", 1).Tostring()
	fmt.Println(c8) //则返回trans_result第一组中的src today

	c9k, c9v := gojson.Json(json1).Get("trans_result").ToArray()
	fmt.Println(c9k, c9v) //[src dst src dst] [today 今天 tomorrow 明天]
	c3k, c3v := gojson.Json(json).Getindex(1).ToArray()
	fmt.Println(c3k, c3v) //    [from] [en]

	json2 := `{"from":"en","to":"zh","trans_result":[{"src":"today","dst":"\u4eca\u5929"},{"src":"tomorrow","dst":"\u660e\u5929"}]}`

	c10 := gojson.Json(json2).Getindex(3).Getindex(1).Getindex(1).Get("src").Tostring()
	fmt.Println(c10) //today

	c11 := gojson.Json(json).Get("result").StringtoArray()
	fmt.Println(c11) //[src today dst 今天]
}

/*
输出结果

&{map[trans_result:map[src:today dst:今天] result:[src today dst 今天] from:en to:zh]}
&{en}
en
today
src
today
[src dst src dst] [today 今天 tomorrow 明天]
[from] [en]
today
[src today dst 今天]


*/
